package com.mzy.linear_struct.面试150题;

/**
 * @Author: mizy3
 * @Date: 2024/08/17/下午5:59
 * @Description:
 */
public class Pro300最长递增子序列 {

    public int lengthOfLIS(int[] nums) {
        // i表示当前数值，dp[i]表示当前数值之前最大的连续递增的长度
        int[] dp = new int[nums.length];
        int ans = 0;
        // dp[i] = dp[j], dp[i - 1]
        for (int i = 0; i < dp.length; i++) {
            dp[i]++;
        }
        for (int i = 1; i < dp.length; i++) {
            for (int j = 0; j < i; j++) {
                if (nums[i] > nums[j]) {
                    //               1 + 1      1    2
                    //                          1
                    dp[i] = Math.max(dp[j] + 1, dp[i]);
                }
            }
            ans = Math.max(ans, dp[i]);
            System.out.println(nums[i] + "  " + dp[i]);
        }

        return dp[dp.length - 1];
    }


    public static void main(String[] args) {
        new Pro300最长递增子序列().lengthOfLIS(new int[]{1,3,6,7,9,4,10,5,6});
    }
}
